<template>
  <el-dialog
    :destroy-close="true"
    :visible.sync="visiable"
    append-to-body
    lock-scroll
    modal
    modal-append-to-body
    show-close
    title="重置密码"
    width="30%"
    @close="close"
  >

    <el-form ref="form" :model="form" :rules="rules">

      <el-form-item label="密码" prop="password">

        <el-input v-model="form.password" show-password type="password" />
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">保存</el-button>
      <el-button @click="close">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { resetUser } from '@/api/api'
import { Message } from 'element-ui'

export default {
  name: 'CoachResetPwdDialog',
  data() {
    return {
      visiable: false,
      form: {
        userId: '',
        password: ''

      },
      rules: {
        password: [{ required: true, message: '请输入重置的密码', trigger: 'blur' },
          { min: 6, message: '长度至少大于6个字符', trigger: 'blur' }]
      }
    }
  },
  methods: {
    confirm() {
      this.requestResetPwd()
    },
    async requestResetPwd() {
      const params = {
        ...this.form
      }
      // const params = {
      //   userId: user?.userId,
      //   password: 'admin123'
      // }
      const { data } = await resetUser(params)
      this.user = []
      if (data.code === 200) {
        Message.success(data.msg)
      } else {
        Message.error(data.msg)
      }

      this.close()
    },
    close() {
      this.visiable = false
      this.$emit('closed')
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
